package com.ITArmy.util;

import com.ITArmy.beans.User;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

public class AddCookie {
    public void addCookie(HttpServletResponse response, User user, boolean freeLogin) {
        if (freeLogin) {
            // 因为uid是int类型的数据（变成字符串）
            Cookie userCookie = new Cookie("uId", user.getuId() + "");
            // 设置Cookie的有效日期为7天
            userCookie.setMaxAge(7 * 24 * 3600);
            // 设置有效路径
            userCookie.setPath("/");
            // 添加cookie信息
            response.addCookie(userCookie);
        }
    }
}
